package com.liguang.rcs.admin.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectUtil {
    public static Object getValue(Field field, Object obj) throws IllegalAccessException {
        boolean isAccess = field.isAccessible();
        try {
            field.setAccessible(true);
            return field.get(obj);
        } finally {
            field.setAccessible(isAccess);
        }
    }


    public static void setValue(Field field, Object obj, Object value) throws IllegalAccessException {
        boolean isAccess = field.isAccessible();
        try {
            field.setAccessible(true);
            field.set(obj, value);
        } finally {
            field.setAccessible(isAccess);
        }
    }

    public static <T> T invokeStaticMethodWithoutParams(Method method) throws InvocationTargetException, IllegalAccessException {
        boolean access = method.isAccessible();
        try {
            return (T) method.invoke(null);
        } finally {
            method.setAccessible(access);
        }
    }

}
